<%@page import="java.sql.Statement"%>
<%@page import="beans.Account"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="Connection.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel='stylesheet' type='text/css' href='css/thread.css' />
<link rel='stylesheet' type='text/css' href='css/index.css' />
<link rel='stylesheet' type='text/css' href='css/style.css' />
<link rel='stylesheet' type='text/css' href='css/menu.css' />
<link rel='stylesheet' type='text/css' href='css/footer.css' />
<title>Hiroom! - ${thread.title}</title>

<style type='text/css'>
.pagination {
	font-size: 13px;
	text-align: center;
	padding: 9px;
	text-align: center;
}

.pagination a {
	text-decoration: none;
}

.pagination span,.pagination a:hover {
	background: none repeat scroll 0% 0% #126183;
}

.pagination a,.cpage {
	padding: 5px 10px;
	margin: 2px;
	border-radius: 3px;
	background: none repeat scroll 0% 0% #29AAE2;
	border: 1px solid;
	color: #F5F5F5;
}
</style>

</head>
<body>
	<%@ include file="CheckLogin.jsp"%>
	<%@ include file="Header.jsp"%>
	<div id='wrapper'>

		<c:if test="${empty param.p || cPage == 1}">
			<div class='main_comment'>
				<div class='box_info'>
					<div class='avatar'>
						<img src="avatar/${thread.account.avatar}" alt="avatar" />
					</div>
					<div class='information'>Bài viết: ${thread.account.numPosts}</div>
				</div>

				<div class='comment'>
					<div class='h_name'>
						<a href='account?do=view&uid=${thread.account.id}'
							style="color:${thread.account.color}">
							${thread.account.fullName}</a>
					</div>
					<h5>${thread.title}</h5>
					<pre>${thread.content}</pre>
					<div class='time'>${thread.posted}
						<c:choose>
							<c:when test="${account.type=='Admin'}">
								<a href='thread?do=del&tid=${thread.id}&bid=${thread.boxID}'
									title='Xóa' class='nof'><img src='images/delete.png'
									alt='Delete' /> </a>
								<a
									href='thread?do=setting&action=hide&tid=${thread.id}&bid=${thread.boxID}'
									title='${thread.state==3||thread.state==4?"Bỏ ẩn":"Ẩn"}'
									class='nof'><img
									src='images/${thread.state==3||thread.state==4?"show":"hide"}.png'
									alt='${thread.state==3||thread.state==4?"Show":"Hide"}' /> </a>
								<a
									href='thread?do=setting&action=close&tid=${thread.id}&bid=${thread.boxID}'
									title='${thread.state==-1||thread.state==2||thread.state==4?"Mở chủ đề":"Đóng chủ đề"}'
									class='nof'><img
									src='images/${thread.state==-1||thread.state==2||thread.state==4?"open":"close"}.png'
									alt='${thread.state==-1||thread.state==2||thread.state==4?"Open":"Close"}' />
								</a>
								<a
									href='thread?do=setting&action=caution&tid=${thread.id}&bid=${thread.boxID}'
									title='${thread.state==1||thread.state==2?"Gỡ chú ý":"Chú ý"}'
									class='nof'><img
									src='images/${thread.state==1||thread.state==2?"caution_sub":"caution_add"}.png'
									alt='${thread.state==1||thread.state==2?"Not Caution":"Caution"}' />
								</a>
								<a href='thread?do=edit&type=thread&tid=${thread.id}'
									title='Sứa đổi' class='nof'><img src='images/edit.png'
									alt='Edit' /></a>
							</c:when>
							<c:when test="${account.type=='SMod'}">
								<a
									href='thread?do=setting&action=hide&tid=${thread.id}&bid=${thread.boxID}'
									title='${thread.state==3||thread.state==4?"Bỏ ẩn":"Ẩn"}'
									class='nof'><img
									src='images/${thread.state==3||thread.state==4?"show":"hide"}.png'
									alt='${thread.state==3||thread.state==4?"Show":"Hide"}' /> </a>
								<a
									href='thread?do=setting&action=close&tid=${thread.id}&bid=${thread.boxID}'
									title='${thread.state==-1||thread.state==2||thread.state==4?"Mở chủ đề":"Đóng chủ đề"}'
									class='nof'><img
									src='images/${thread.state==-1||thread.state==2||thread.state==4?"open":"close"}.png'
									alt='${thread.state==-1||thread.state==2||thread.state==4?"Open":"Close"}' />
								</a>
								<a
									href='thread?do=setting&action=caution&tid=${thread.id}&bid=${thread.boxID}'
									title='${thread.state==1||thread.state==2?"Gỡ chú ý":"Chú ý"}'
									class='nof'><img
									src='images/${thread.state==1||thread.state==2?"caution_sub":"caution_add"}.png'
									alt='${thread.state==1||thread.state==2?"Not Caution":"Caution"}' />
								</a>
								<a href='thread?do=edit&type=thread&tid=${thread.id}'
									title='Sứa đổi' class='nof'><img src='images/edit.png'
									alt='Edit' /></a>
							</c:when>
							<c:when test="${account.type=='Mod'}">
								<a
									href='thread?do=setting&action=hide&tid=${thread.id}&bid=${thread.boxID}'
									title='${thread.state==3||thread.state==4?"Bỏ ẩn":"Ẩn"}'
									class='nof'><img
									src='images/${thread.state==3||thread.state==4?"show":"hide"}.png'
									alt='${thread.state==3||thread.state==4?"Show":"Hide"}' /> </a>
								<a
									href='thread?do=setting&action=close&tid=${thread.id}&bid=${thread.boxID}'
									title='${thread.state==-1||thread.state==2||thread.state==4?"Mở chủ đề":"Đóng chủ đề"}'
									class='nof'><img
									src='images/${thread.state==-1||thread.state==2||thread.state==4?"open":"close"}.png'
									alt='${thread.state==-1||thread.state==2||thread.state==4?"Open":"Close"}' />
								</a>
								<a href='thread?do=edit&type=thread&tid=${thread.id}'
									title='Sứa đổi' class='nof'><img src='images/edit.png'
									alt='Edit' /></a>
							</c:when>
						</c:choose>
					</div>
				</div>
			</div>
		</c:if>

		<c:forEach var="comment" items="${thread.comments}" varStatus="status">
			<div class='box_comment'>
				<div class='box_info'>
					<div class='avatar'>
						<img src="avatar/${comment.account.avatar}" alt="avatar" />
					</div>
					<div class='information'>Bài viết:
						${comment.account.numPosts}</div>
				</div>

				<div class='comment'>
					<div class='h_name' style="color:${comment.account.color}">
						<a href='account?do=view&uid=${comment.account.id}'
							style="color:${comment.account.color}">${comment.account.fullName}</a>
						<span>#${(cPage-1)*size+status.index+1}</span>
					</div>
					<pre>${comment.content}</pre>
					<div class='time'>${comment.time}
						<c:choose>
							<c:when test="${account.type=='Admin'}">
								<a href='thread?do=delc&cid=${comment.id}&tid=${thread.id}'
									title='Xóa' class='nof'><img src='images/delete.png'
									alt='Delete' /></a>
								<a href='thread?do=edit&type=comment&cid=${comment.id}'
									title='Sứa đổi' class='nof'><img src='images/edit.png'
									alt='Edit' /></a>
							</c:when>
							<c:when test="${account.type=='SMod'||account.type=='Mod'}">
								<a href='thread?do=edit&type=comment&cid=${comment.id}'
									title='Sứa đổi' class='nof'><img src='images/edit.png'
									alt='Edit' /></a>
							</c:when>
						</c:choose>
					</div>
				</div>
			</div>
		</c:forEach>

		<c:if test="${sumPage>1}">
			<div class="pagination">
				<a
					href="?do=view&tid=${param.tid}&sz=${size}&p=${cPage>1?cPage-1:1}"
					title="Trang trước">&lt;</a>
				<c:forEach var="i" begin="1" end="${sumPage}">
					<c:choose>
						<c:when test="${i==cPage}">
							<span class="cpage">${i}</span>
						</c:when>
						<c:otherwise>
							<a href="?do=view&tid=${param.tid}&sz=${size}&p=${i}">${i}</a>
						</c:otherwise>
					</c:choose>
				</c:forEach>
				<a
					href="?do=view&tid=${param.tid}&sz=${size}&p=${cPage<sumPage?cPage+1:sumPage}"
					title="Trang kế">&gt;</a>
			</div>
		</c:if>

		<!--post bai tra loi-->
		<c:if test="${thread.state!=-1&&thread.state!=2&&thread.state!=4}">
			<div id='post_cmm'>
				<div class='avatar'>
					<img src="avatar/${account.avatar}" alt="avatar" />
				</div>
				<form action="thread?do=comment&tid=${param.tid}&sz=${size}"
					method='post'>
					<textarea placeholder='Nội dung bài post ở đây' name='content'></textarea>
					<button class='button' type='submit' name='ok'>Gửi bài</button>
					<!-- <button class='button' type='button' name='preview'>Xem
						trước</button> -->
				</form>
			</div>
		</c:if>

	</div>
	<div class='clr'></div>

	<jsp:include page="Footer.jsp"></jsp:include>
</body>
</html>